package com.rokyinfo.generator;

/**
 * Created by yuanzhijian on 2017/2/4.
 */
public class MacAddressGenerator {

    /**
     * 生产MAC 地址
     * @param lastBTAddr
     * @param i
     * @return
     */
    public static String generateMacAddr(String lastBTAddr,int i) {

        long baseAddress = Long.parseLong(lastBTAddr.replaceAll(":", ""),
                16);

        long btAddressIncreased = baseAddress + i + 1;

        StringBuffer macAddr = new StringBuffer(
                Long.toHexString(btAddressIncreased));
        while (macAddr.length() < 12) {
            macAddr.insert(0, "0");
        }

        macAddr.insert(2, ":");
        macAddr.insert(5, ":");
        macAddr.insert(8, ":");
        macAddr.insert(11, ":");
        macAddr.insert(14, ":");

        return macAddr.toString();
    }

}
